import {Injectable} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import {ChangeCategoryEventEmitter} from './change-category-event-emitter';

@Injectable()
export class PubSubService{
   static instance: PubSubService;
   static isCreating: Boolean = false;
   
   public changeCategory: ChangeCategoryEventEmitter;
   
   constructor(){
       if (!PubSubService.isCreating) {
            throw new Error("You can't call new in Singleton instances!");
       }
   }
   
   static getInstance() {
        if (PubSubService.instance == null) {
            PubSubService.isCreating = true;
            
            PubSubService.instance = new PubSubService();
            PubSubService.instance.changeCategory = new ChangeCategoryEventEmitter();
            
            PubSubService.isCreating = false;
        }
 
        return PubSubService.instance;
    }
}